package com.wolfcode.customerlinkmane.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.common.utils.poi.ExcelUtil;
import com.wolfcode.customerlinkmane.domain.CustomerLinkmane;
import com.wolfcode.customerlinkmane.domain.vo.CustomerLinkmaneInfo;
import com.wolfcode.customerlinkmane.domain.vo.CustomerLinkmaneUpdateVo;
import com.wolfcode.customerlinkmane.domain.vo.CustomerLinkmaneVo;
import com.wolfcode.customerlinkmane.service.ICustomerLinkmaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户联系人Controller
 * 
 * @author wolfcode
 * @date 2022-12-09
 */
@RestController
@RequestMapping("/customerlinkmane/linkmane")
public class CustomerLinkmaneController extends BaseController
{
    @Autowired
    private ICustomerLinkmaneService customerLinkmaneService;

    /**
     * 查询客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerLinkmane customerLinkmane)
    {
        startPage();
        List<CustomerLinkmaneInfo> list = customerLinkmaneService
                .selectCustomerLinkmaneList(customerLinkmane);
        return getDataTable(list);
    }

    /**
     * 导出客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:export')")
    @Log(title = "客户联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerLinkmane customerLinkmane)
    {
        List<CustomerLinkmaneInfo> list = customerLinkmaneService.selectCustomerLinkmaneList(customerLinkmane);
        ExcelUtil<CustomerLinkmaneInfo> util = new ExcelUtil<CustomerLinkmaneInfo>(CustomerLinkmaneInfo.class);
        util.exportExcel(response, list, "客户联系人数据");
    }

    /**
     * 获取客户联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return AjaxResult.success(customerLinkmaneService.selectCustomerLinkmaneById(id));
    }

    /**
     * 新增客户联系人
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:add')")
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public void add(@RequestBody CustomerLinkmaneVo linkmaneVo)
    {
       customerLinkmaneService.insertCustomerLinkmane(linkmaneVo);
    }

    /**
     * 修改客户联系人
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:edit')")
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit(@RequestBody CustomerLinkmaneUpdateVo linkmaneVo)
    {
        System.out.println(linkmaneVo);
        customerLinkmaneService.updateCustomerLinkmane(linkmaneVo);
    }

    /**
     * 删除客户联系人
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:remove')")
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerLinkmaneService.deleteCustomerLinkmaneByIds(ids));
    }

    /**
     * 通过客户id查询客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('customerlinkmane:linkmane:listAll')")
    @GetMapping("/listAll/{id}")
    public AjaxResult listAll(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerLinkmaneService.selectCustomerLinkmaneListAll(id));
    }
}
